package org.zjx.message;

import com.alibaba.fastjson2.annotation.JSONType;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.Map;

@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@JSONType(typeName = "NOTIFICATION")
public class NotificationMessage extends Message {
    private String topic;       // 通知主题/频道
    private String title;       // 通知标题
    private String content;     // 通知内容
    private Map<String, Object> data; // 附加数据

    public NotificationMessage(String topic, String title) {
        this.topic = topic;
        this.title = title;
        setType(MessageType.NOTIFICATION);
        setTimestamp(System.currentTimeMillis());
    }

    public NotificationMessage(String topic, String title, String content) {
        this(topic, title);
        this.content = content;
    }

    public NotificationMessage(String topic, String title, Map<String, Object> data) {
        this(topic, title);
        this.data = data;
    }

    /**
     * 添加附加数据
     */
    public NotificationMessage addData(String key, Object value) {
        if (this.data == null) {
            this.data = new java.util.HashMap<>();
        }
        this.data.put(key, value);
        return this;
    }
}